<?php
class Mauthor extends CI_Model{
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }

    public function getAuthor(){
        $this->db->select(' id, name, gender, birthday, nation');
        $this->db->from('author');
        $this->db->order_by('id', 'desc');
        $query = $this->db->get();
        return $query->result_array();
    }

    public function getAuthorByID($author_id){
        $this->db->select(' id, name, gender, birthday, nation');
        $this->db->from('author');
        $this->db->where('id',$author_id);
        $query = $this->db->get();
        return $query->row_array();
    }

    public function insertAuthor($param){
        $data = array(
            'id' => NULL,
            'name' => $param['name'],
            'gender' => $param['gender'],
            'birthday' => $param['birthday'],
            'nation' => $param['nation']
        );
        $this->db->insert('author', $data); 
    }

    public function updateAuthor($param){
        $data = array(
            'name' => $param['name'],
            'gender' => $param['gender'],
            'birthday' => $param['birthday'],
            'nation' => $param['nation']
        );
        $this->db->where('id', $param['id']);
        $this->db->update('author', $data);
    }

    public function deteleAuthor($author_id){
        $this->db->where('id', $author_id);
        $this->db->delete('author');
    }
}
?>